import threading
import time
import urllib.request
import json
import csv

vins_file = "../registerdb/vins_org.csv"



def rest(apiname, values={"vins": ["SXQC0512"]}):
    opener = urllib.request.build_opener()
    request = urllib.request.Request('http://172.16.8.91:5066/%s' % apiname,
                                     json.dumps(values).encode(encoding='utf8'))
    response = opener.open(request)
    print(response.read().decode("utf8"))


def run_rest():
    csvfile = csv.reader(open(vins_file, 'r'))
    for line in csvfile:
        vin = line[0]
        data = {"vins": [vin],"cmd":[0x01]}
        apiname = "QueryParameters"
        rest(apiname,data)


if __name__ == '__main__':
    run_rest()
